package com.esd.db.service.impl;

import java.security.GeneralSecurityException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.mail.MessagingException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.esd.db.dao.VtdParameterMapper;
import com.esd.db.dao.inspectorrecordMapper;
import com.esd.db.dao.taskMapper;
import com.esd.db.dao.workerRecordMapper;
import com.esd.db.model.AlipayInfo;
import com.esd.db.model.VtdParameter;
import com.esd.db.model.inspectorrecord;
import com.esd.db.model.workerRecord;
import com.esd.db.service.WorkerRecordService;
import com.esd.db.tool.TaskMovedToWorker939MailSender;

@Service("WorkerRecordService")
public class WorkerRecordServiceImpl implements WorkerRecordService {

	@Autowired
	workerRecordMapper workerRecordMapper;
	
	@Autowired
	taskMapper taskMapper;
	
	@Autowired
	VtdParameterMapper paramMapper;
	
	@Autowired
	inspectorrecordMapper inspectorrecordMapper;
	
	@Override
	public synchronized int deleteByPrimaryKey(Integer recordId) {

		return workerRecordMapper.deleteByPrimaryKey(recordId);
	}

	@Override
	public synchronized int insert(workerRecord record) {

		return workerRecordMapper.insert(record);
	}

	@Override
	public  int insertSelective(workerRecord record) {

		return workerRecordMapper.insertSelective(record);
	}

	@Override
	public synchronized workerRecord getByPrimaryKey(Integer recordId) {

		return workerRecordMapper.selectByPrimaryKey(recordId);
	}

	@Override
	public  int updateByPrimaryKeySelective(workerRecord record) {

		return workerRecordMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public synchronized int updateByPrimaryKey(workerRecord record) {

		return workerRecordMapper.updateByPrimaryKey(record);
	}

	@Override
	public  List<workerRecord> getDoingTask() {

		return workerRecordMapper.selectDoingTask();
	}

	@Override
	public  List<workerRecord> getAllByWorkerId(Integer workerId, Integer taskEffective, Integer statu, String beginDate, String endDate, String taskNameCondition, int page, int row, int dateType) {
		Map<String, Object> map = new HashMap<String, Object>();
		if (page == 0) {
			map.put("begin", null);
			map.put("end", null);
		} else {
			map.put("begin", ((page - 1) * row));
			map.put("end", row);
		}

		map.put("workerId", workerId);
		map.put("statu", statu);
		map.put("taskEffective", taskEffective);
		if (dateType > 0) {
			map.put("dateType", dateType);
		}
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		if (taskNameCondition.trim().length() > 0) {
			map.put("taskNameCondition", taskNameCondition);
		}
		return workerRecordMapper.selectAllByWorkerId(map);
	}

	@Override
	public  int getAllCountByWorkerId(Integer workerId, Integer statu, String beginDate, String endDate, String taskNameCondition, int dateType) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("dateType", dateType);
		map.put("workerId", workerId);
		map.put("statu", statu);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		if (taskNameCondition.trim().length() > 0) {
			map.put("taskNameCondition", taskNameCondition);
		}
		return workerRecordMapper.selectAllCountByWorkerId(map);
	}

	@Override
	public synchronized String get1DownUrlByTaskName(String taskName) {

		return workerRecordMapper.selectDownUrlByTaskName(taskName);
	}

	@Override
	public synchronized int get1PkIDByTaskName(String taskName) {

		return workerRecordMapper.selectPkIDByTaskName(taskName);
	}

	@Override
	public  workerRecord getWorkerRecordByWorkerId(Integer workerId) {

		return workerRecordMapper.selectWorkerRecordByWorkerId(workerId);
	}

	@Override
	public  int getDoingTaskCountByWorkerId(Integer workerId) {
		return workerRecordMapper.selectDoingTaskCountByWorkerId(workerId);
	}

	@Override
	public  int getTaskCountByDownPackName(String downPackName) {

		return workerRecordMapper.selectTaskCountByDownPackName(downPackName);
	}

	@Override
	public  int getPackStatuByDownPackName(String downPackName) {

		return workerRecordMapper.selectPackStatuByDownPackName(downPackName);
	}

	@Override
	public synchronized List<workerRecord> getDownNameAndTimeByWorkerIdGroupByDownPackName(Integer workerId) {

		return workerRecordMapper.selectDownNameAndTimeByWorkerIdGroupByDownPackName(workerId);
	}

	@Override
	public  List<workerRecord> getAllByDownPackName(String downPackName) {

		return workerRecordMapper.selectAllByDownPackName(downPackName);
	}

	@Override
	public  int getFinishTaskCountByPackId(Integer packId, Integer taskMarkTime) {
		Map<String, Object> map = new HashMap<>();
		map.clear();
		map.put("packId", packId);
		map.put("taskMarkTime", taskMarkTime);
		return workerRecordMapper.selectFinishTaskCountByPackId(map);
	}

	@Override
	public synchronized String get1DownPackNameByTaskName(String taskName) {

		return workerRecordMapper.selectDownPackNameByTaskName(taskName);
	}

	@Override
	public synchronized String getDownUrlByDownPackName(String downPackName) {
		return workerRecordMapper.selectDownUrlByDownPackName(downPackName);
	}

	@Override
	public synchronized List<workerRecord> getDownNameAndTimeByWorkerIdPagesGroupByDownPackName(Map<String, Integer> map) {

		return workerRecordMapper.selectDownNameAndTimeByWorkerIdPagesGroupByDownPackName(map);
	}

	@Override
	public  int getPkIDByTaskId(Integer taskId) {

		return workerRecordMapper.selectPkIDByTaskId(taskId);
	}

	/**
	 * 模糊查询下载包名符合的数量
	 */
	public  int getDownPackNameCountByworkerIdGroupByDownPackName(int workerId, String downPackName) {
		Map<String, Object> pageMap = new HashMap<String, Object>();

		pageMap.put("workerId", workerId);
		if (downPackName.trim().length() > 0)
			pageMap.put("downPackName", downPackName);

		return workerRecordMapper.selectDownPackNameCountByworkerIdGroupByDownPackName(pageMap);
	}

	/**
	 * 模糊查询 by downPackName 分页
	 */
	public  List<workerRecord> getWorkerRecordLikeDownPackName(int workerId, int page, String downPackName, int row) {
		Map<String, Object> pageMap = new HashMap<String, Object>();
		pageMap.put("begin", ((page - 1) * row));
		pageMap.put("end", row);
		pageMap.put("workerId", workerId);
		if (downPackName.trim().length() > 0)
			pageMap.put("downPackName", downPackName);

		return workerRecordMapper.selectWorkerRecordLikeDownPackName(pageMap);
	}

	@Override
	public  Double getTaskMarkTimeMonthByWorkerIdAndMonth(int workerId, String beginDate, String endDate, String userNameCondition, int taskEffective, int taskStatus, int dateType) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.clear();
		if (workerId > 0) {
			map.put("workerId", workerId);
		}
		if (beginDate.trim().length() > 0) {
			map.put("beginDate", beginDate);
			map.put("endDate", endDate);
		}

		if (userNameCondition == null || userNameCondition.trim().length() == 0 ) {
			map.put("userNameCondition", null);
		} else {
			map.put("userNameCondition", userNameCondition);
		}
		map.put("taskEffective", taskEffective);
		map.put("taskStatus", taskStatus);
		map.put("dateType", dateType);
		return workerRecordMapper.selectTaskMarkTimeMonthByWorkerIdAndMonth(map);
	}

	@Override
	public  Double getSUMTaskMarkTimeByPackId(int packId) {

		return workerRecordMapper.selectSUMTaskMarkTimeByPackId(packId);
	}

	@Override
	public synchronized int getPackIdByTaskId(Integer task_id) {

		return workerRecordMapper.selectPackIdByTaskId(task_id);
	}

	@Override
	public  int updateBydownPackName(workerRecord record) {

		return workerRecordMapper.updateBydownPackName(record);
	}

	@Override
	public  List<Map<String, Object>> getWorkerIdGroupByWorkerId(int inspectorId,String userName, int timeMark, int taskStatu, int taskEffective, int page, int row,int limitMin,String workGroupCode) {
		Map<String, Object> map = new HashMap<>();

		map.clear();
		if (page == 0) {
			map.put("begin", null);
			map.put("end", null);
		} else {
			map.put("begin", ((page - 1) * row));
			map.put("end", row);
		}
		if (userName.isEmpty() || userName.trim().length() == 0) {
			map.put("userName", null);
		} else {
			map.put("userName", userName);
		}
		if(inspectorId == -1){
			map.put("inspectorId", null);
		}else if(inspectorId >= 0){
			map.put("inspectorId", inspectorId);
		}
		if(workGroupCode!=null && (!workGroupCode.equals(""))){
			map.put("workGroupCode", workGroupCode);
		}
//		map.put("limitMin",limitMin);    //去掉初审的时间选择条件  20161223
//		map.put("timeMark", timeMark);   //去掉初审的时间选择条件  20161223
		map.put("taskStatu", taskStatu);
		map.put("taskEffective", taskEffective);
		return workerRecordMapper.selectWorkerIdGroupByWorkerId(map);
	}

	@Override
	public  int updateByWorkerId(int taskEffective, int taskLockTime, int workerId, String firstDate, int inspectorId, String endDate, int inspectorrecordId) {
		Map<String, Object> map = new HashMap<>();
		map.clear();
		map.put("workerId", workerId);
		if (taskEffective == 0) {
			map.put("taskEffective", 2);
			map.put("taskMarkTime", 0.00);
		} else if (taskEffective == 1) {
			map.put("taskEffective", 1);
		}
		if (taskLockTime == 0) {
			map.put("taskLockTime", null);
		} else if(taskLockTime > 0){
			map.put("taskLockTime", taskLockTime * 3600 * 1000);
		}
		if (inspectorrecordId > 0) {
			map.put("inspectorrecordId", inspectorrecordId);
		}
		if (firstDate.trim().length() > 0){
			map.put("firstDate", firstDate);
			map.put("endDate", endDate);
		}
		if(inspectorId > 0){
			map.put("inspectorId", inspectorId);
		}	
		return workerRecordMapper.updateByWorkerId(map);
	}

	@Override
	public  int getWorkerIdCountGroupByWorkerId(int inspectorId,String userName, int timeMark, int taskStatu, int taskEffective,int limitMin,String workGroupCode) {
		Map<String, Object> map = new HashMap<>();

		map.clear();
		if (userName.isEmpty() || userName.trim().length() == 0) {
			map.put("userName", null);
		} else {
			map.put("userName", userName);
		}
		if(inspectorId == -1){
			map.put("inspectorId", null);
		}else if(inspectorId >= 0){
			map.put("inspectorId", inspectorId);
		}
		if(workGroupCode!=null && (!workGroupCode.equals(""))){
			map.put("workGroupCode", workGroupCode);
		}
//		map.put("limitMin", limitMin);     //去掉初审的时间选择条件  20161223
//		map.put("timeMark", timeMark);     //去掉初审的时间选择条件  20161223
		map.put("taskStatu", taskStatu);
		map.put("taskEffective", taskEffective);
		return workerRecordMapper.selectWorkerIdCountGroupByWorkerId(map);
	}

	@Override
	public  List<workerRecord> getByWorkerIdAndEffective(int workerId, int taskEffective, int taskStatu) {
		Map<String, Object> map = new HashMap<>();
		map.clear();
		map.put("workerId", workerId);
		map.put("taskEffective", taskEffective);
		map.put("taskStatu", taskStatu);
		return workerRecordMapper.selectByWorkerIdAndEffective(map);
	}

	@Override
	public  int updateByGiveUp(int workerId, int taskId, int version, String updateMethod) {
		Map<String, Object> map = new HashMap<>();
		map.clear();
		map.put("taskStatu", 3);
		map.put("updateMethod", updateMethod);
		map.put("workerId", workerId);
		map.put("taskId", taskId);	
		if (version == 0) {
			map.put("version", null);
		} else if (version > 0) {
			map.put("version", version);
		}

		return workerRecordMapper.updateByGiveUp(map);
	}

	@Override
	public  int getCountByWorkerId(Integer workerId, Integer statu, int taskEffective) {
		Map<String, Object> map = new HashMap<>();
		map.clear();
		map.put("workerId", workerId);
		map.put("statu", statu);
		map.put("taskEffective", taskEffective);
		return workerRecordMapper.selectCountByWorkerId(map);
	}

	@Override
	public  List<Integer> getPackIdByDateTime(int workerId, String firstDate, String endDate) {
		Map<String, Object> map = new HashMap<>();
		map.clear();
		map.put("workerId", workerId);
		map.put("firstDate", firstDate);
		map.put("endDate", endDate);

		return workerRecordMapper.selectPackIdByDateTime(map);
	}

	@Override
	public synchronized List<workerRecord> getInvalidTask(int page, int row) {
		Map<String, Object> map = new HashMap<>();
		if (page == 0) {
			map.put("begin", null);
			map.put("end", null);
		} else {
			map.put("begin", ((page - 1) * row));
			map.put("end", row);
		}
		return workerRecordMapper.selectInvalidTask(map);
	}

	@Override
	public synchronized Integer getInvalidCountTask() {

		return workerRecordMapper.selectInvalidCountTask();
	}

	@Override
	public synchronized int updateByInvalid(int inspectorId, int taskId) {
		Map<String, Object> map = new HashMap<>();
		map.put("inspectorId", inspectorId);
		map.put("taskId", taskId);
		return workerRecordMapper.updateByInvalid(map);
	}

	@Override
	public  int getTaskMarkTimeZeroCountByPackId(Integer packId) {

		return workerRecordMapper.selectTaskMarkTimeZeroCountByPackId(packId);
	}

	@Override
	public  int getdownCountByWorkerIdAndDate(int workerId, int dateType, String beginDate, String endDate) {
		Map<String, Object> map = new HashMap<>();
		map.clear();
		map.put("workerId", workerId);
		map.put("dateType", dateType);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		return workerRecordMapper.selectdownCountByWorkerIdAndDate(map);
	}

	@Override
	public  int getCountByWorkerIdAndDate(int workerId, int dateType, String beginDate, String endDate, int taskStatu, int taskEffective) {
		Map<String,Object> map = new HashMap<>();
		map.clear();
		map.put("workerId", workerId);
		map.put("dateType", dateType);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		map.put("taskStatu", taskStatu);
		if (taskStatu == 3 || taskStatu == 2) {
			map.put("taskEffective", null);
		} else {
			map.put("taskEffective", taskEffective);
		}
		return workerRecordMapper.selectCountByWorkerIdAndDate(map);
	}

	@Override
	public List<Map<String, Object>> getMoneyList(String beginDate, String endDate, int month) {
		Map<String,Object> map = new HashMap<>();
		if(month>0){
			map.put("month",month);
		}else{
			map.put("beginDate", beginDate);
			map.put("endDate", endDate);
		}
		return workerRecordMapper.selectMoneyList(map);
	}

	@Override
	public List<workerRecord> getAllRowByTaskId(int taskId) {
		
		return workerRecordMapper.selectAllRowByTaskId(taskId);
	}

	@Override
	public Date getTaskUploadTimeByWorkerId(int workerId) {
		
		return workerRecordMapper.selectTaskUploadTimeByWorkerId(workerId);
	}

	@Override
	public List<workerRecord> getTaskByWorkerId(int inspectorId, int workerId, int taskEffective, int taskStatus, String workGroupCode, String uploadUUID) {
		Map<String, Object> map = new HashMap<>();
		if(inspectorId == -1){
			map.put("inspectorId", null);
		}else if(inspectorId > 0){
			map.put("inspectorId", inspectorId);
		}
		if(workGroupCode!=null && (!workGroupCode.equals(""))){
			if(workGroupCode.equals("0")){   //审核管理账号  默认为0
				map.put("workGroupCode", null);
			}else{
				map.put("workGroupCode", workGroupCode);
			}
		}
		if(uploadUUID != null){
			map.put("uploadUUID", uploadUUID);
		}else{
			map.put("uploadUUID", null);
		}
		map.put("workerId", workerId);
		map.put("taskEffective", taskEffective);
		map.put("taskStatus", taskStatus);
		return workerRecordMapper.selectTaskByWorkerId(map);
	}

	//更新审核结果
	public int updateAduitByWorkerId2(int workerId, int taskEffective, int taskLockTime, int inspectorId, 
			int inspectorrecordId, List<String> downPackNames, int salaryCountFlag, String uploadUUID, int sendBackType, 
			int[] unqualifiedTaskIds, AlipayInfo payInfo) {
		Map<String, Object> map = new HashMap<>();
		map.put("workerId", workerId);
		if(taskEffective == 0){
			map.put("taskEffective",2);
			map.put("downPackNames", downPackNames);
		}else{
			map.put("taskEffective",taskEffective);
			map.put("downPackNames", null);
		}
		
		if(taskLockTime>0){
			map.put("taskLockTime", taskLockTime);
		}else{
			map.put("taskLockTime", null);
		}
		map.put("inspectorId", inspectorId);
		if(inspectorrecordId>0){
			map.put("inspectorrecordId", inspectorrecordId);
		}else{
			map.put("inspectorrecordId", null);
		}
		map.put("salaryCountFlag", salaryCountFlag);
		map.put("uploadUUID", uploadUUID);
		map.put("sendBackType", sendBackType);
		map.put("unqualifiedTaskIds", unqualifiedTaskIds);
		//更新支付宝支付字段  需要在更新审核状态之前更新
		if(payInfo != null){
			map.put("OutBizNo", payInfo.getOutBizNo());
			map.put("alipayWorkerId", payInfo.getWorkerId());
			workerRecordMapper.updateAlipayOutBizNoForInspectByWorker(map);
		}
		return workerRecordMapper.updateAduitByWorkerId2(map);
	}

	@Override
	public List<Integer> getPackIdByDateTime2(int workerId) {
		Map<String, Object> map = new HashMap<>();
		map.put("workerId", workerId);
		return workerRecordMapper.selectPackIdByDateTime2(map);
	}

	@Override
	public List<Map<String, Object>> getWorkerHis(int workerId, int page, int row) {
		Map<String, Object> map = new HashMap<>();
		map.put("workerId", workerId);
		if (page == 0) {
			map.put("begin", null);
			map.put("end", null);
		} else {
			map.put("begin", ((page - 1) * row));
			map.put("end", row);
		}
		return workerRecordMapper.selectWorkerHis(map);
	}
	
	//通过taskId查询是否有正在进行中的任务（cx-20160126）
	public int getDoingCountByTaskId(int taskId) {

		return workerRecordMapper.selectDoingCountByTaskId(taskId);
	}
	
	@Override
	public int inserts(List<workerRecord> list) {
			
		return workerRecordMapper.inserts(list);
	}

	@Override
	public List<Map<String, Object>> getListForInspectorByDay(String dateCondition,int page,int row,String workGroupCode, String nowString) {
		Map<String,Object> map = new HashMap<String, Object>();
		if (page == 0) {
			map.put("begin", null);
			map.put("end", null);
		} else {
			map.put("begin", ((page - 1) * row));
			map.put("end", row);
		}
		if(dateCondition.trim().length() == 0){
			map.put("dateCondition", null);
		}else{
			map.put("dateCondition", dateCondition);
		}
		map.put("workGroupCode", workGroupCode);
		map.put("nowString", nowString);
		return workerRecordMapper.selectForInspectorByDay(map);
	}

	@Override
	public int getCountForInspectorByDay(String dateCondition,String workGroupCode,String nowString) {
		Map<String,Object> map = new HashMap<String, Object>();
		if(dateCondition.trim().length() == 0){
			map.put("dateCondition", null);
		}else{
			map.put("dateCondition", dateCondition);
		}
		map.put("workGroupCode", workGroupCode);
		map.put("nowString", nowString);
		return workerRecordMapper.selectForCountInspectorByDay(map);
	}

	@Override
	public List<workerRecord> getTaskForInspectorByDay(String insDate, String searchTime, String workGroupCode, int inspectorId) {
		Map<String,Object> map = new HashMap<String, Object>();
		if(insDate.trim().length() == 0){
			map.put("insDate", null);
		}else{
			map.put("insDate", insDate);
		}
		map.put("workGroupCode", workGroupCode);
		map.put("searchTime", searchTime);
		map.put("inspectorId", inspectorId);
		return workerRecordMapper.selectTaskForInspectorByDay(map);
	}

	@Override
	public int updateAduitForInspectByDay(String insDate, int taskEffective, int taskLockTime, int inspectorId,
			int inspectorrecordId, int[] workerIds,String searchTime, 
			String workGroupCode, int salaryCountFlag, List<AlipayInfo> payList,  List<Integer> recordIds) {
		Map<String, Object> map = new HashMap<>();
		map.put("insDate", insDate);
		if(taskEffective == 0){
			map.put("taskEffective",2);
		}else{
			map.put("taskEffective",taskEffective);
		}
		
		if(taskLockTime>0){
			map.put("taskLockTime", taskLockTime);
		}else{
			map.put("taskLockTime", null);
		}
		map.put("inspectorId", inspectorId);
		if(inspectorrecordId>0){
			map.put("inspectorrecordId", inspectorrecordId);
		}else{
			map.put("inspectorrecordId", null);
		}
		if(workerIds!=null){
			map.put("workerIds", workerIds);			
		}else{
			map.put("workerIds", null);		
		}
		map.put("workGroupCode", workGroupCode);
		map.put("searchTime", searchTime);
		if(salaryCountFlag==9){
			map.put("salaryCountFlag", null);
		}else{
			map.put("salaryCountFlag", salaryCountFlag);
		}
		map.put("recordIds", recordIds);
		//更新支付宝支付字段  需要在更新审核状态之前更新
		if(payList != null && (!payList.isEmpty())){
			for (AlipayInfo a : payList) {
				map.put("OutBizNo", a.getOutBizNo());
				map.put("alipayWorkerId", a.getWorkerId());
				workerRecordMapper.updateAlipayOutBizNoForInspectByDay(map);
			}
		}
		return workerRecordMapper.updateAduitForInspectByDay(map);
		
	}

	@Override
	public List<Integer> getPackIdForinspectorByPackage() {
		return workerRecordMapper.getPackIdForinspectorByPackage();
	}

	@Override
	public int getTaskCountByPackIdForInspectorByPackage(Integer packId) {
		Map<String, Object> map = new HashMap<>();
		map.put("packId", packId);
		return workerRecordMapper.selectTaskCountByPackIdForInspectorByPackage(map);
	}

	@Override
	public List<Map<String, Object>> getListForInspectorByPackage(List<Integer> packIds, String insPackageCondition, int page, int row) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("packIds", packIds);
		if (page == 0) {
			map.put("begin", null);
			map.put("end", null);
		} else {
			map.put("begin", ((page - 1) * row));
			map.put("end", row);
		}
		if(insPackageCondition.trim().length() == 0){
			map.put("packName", null);
		}else{
			map.put("packName", insPackageCondition);
		}
		return workerRecordMapper.selectForInspectorByPackage(map);
	}

	@Override
	public int getCountForInspectorByPackage(List<Integer> packIds,String insPackageCondition) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("packIds", packIds);
		if(insPackageCondition.trim().length() == 0){
			map.put("packName", null);
		}else{
			map.put("packName", insPackageCondition);
		}
		return workerRecordMapper.selectCountForInspectorByPackage(map);
	}

	@Override
	public List<workerRecord> getTaskForInspectorByPackage(int packId) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("packId", packId);
		return workerRecordMapper.selectTaskForInspectorByPackage(map);
	}

	@Override
	public List<Integer> getWorkIdsByPackId(int packId) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("packId", packId);
		return workerRecordMapper.selectWorkIdsByTaskId(map);
	}

	@Override
	public int updateAduitForInspectByPackage(int packId, int taskEffective, int taskLockTime, int inspectorId, 
			int inspectorrecordId, int[] workerIds, int sendBackType, int[] unqualifiedTaskIds, int salaryCountFlag, List<AlipayInfo> payList) {
		Map<String, Object> map = new HashMap<>();
		map.put("packId", packId);
		if(taskEffective == 0){
			map.put("taskEffective",2);
		}else{
			map.put("taskEffective",taskEffective);
		}
		if(taskLockTime>0){
			map.put("taskLockTime", taskLockTime);
		}else{
			map.put("taskLockTime", null);
		}
		map.put("inspectorId", inspectorId);
		if(inspectorrecordId>0){
			map.put("inspectorrecordId", inspectorrecordId);
		}else{
			map.put("inspectorrecordId", null);
		}
		if(workerIds!=null){
			map.put("workerIds", workerIds);			
		}else{
			map.put("workerIds", null);		
		}
		map.put("sendBackType", sendBackType);
		map.put("unqualifiedTaskIds", unqualifiedTaskIds);
		
		if(salaryCountFlag==9){
			map.put("salaryCountFlag", null);
		}else{
			map.put("salaryCountFlag", salaryCountFlag);
		}
		//更新支付宝支付字段  需要在更新审核状态之前更新
		if(payList != null && (!payList.isEmpty())){
			for (AlipayInfo a : payList) {
				map.put("OutBizNo", a.getOutBizNo());
				map.put("alipayWorkerId", a.getWorkerId());
				workerRecordMapper.updateAlipayOutBizNoForInspectByPackage(map);
			}
		}
		
		return workerRecordMapper.updateAduitForInspectByPackage(map);
	}

	@Override
	public List<Map<String,Integer>> getTaskIdsAndWorkerrecordIdsforInspectByDay(String insDate, String searchTime, String workGroupCode,int inspectorId) {
		Map<String, Object> map = new HashMap<>();
		map.put("insDate", insDate);
		map.put("workGroupCode", workGroupCode);
		map.put("searchTime", searchTime);
		map.put("inspectorId", inspectorId);
		return workerRecordMapper.selectTaskIdsforInspectByDay(map);
	}

	@Override
	public List<Integer> getTaskIdsforInspectByPackage(int packId) {
		Map<String, Object> map = new HashMap<>();
		map.put("packId", packId);
		return workerRecordMapper.selectTaskIdsforInspectByPackage(map);
	}

	@Override
	public List<Integer> getTaskIdsforInspectByPackageAndMarkTimeIsZero(int packId, int inspType) {
		Map<String, Object> map = new HashMap<>();
		map.put("packId", packId);
		if(inspType == 1){   //1是按包审核
			map.put("taskEffective", 4);
		}else{//2是快速审核
			map.put("taskEffective", 3);
		}
		return workerRecordMapper.selectTaskIdsforInspectByPackageAndMarkTimeIsZero(map);
	}

	@Override
	public int updateAduitForInspectByPackageAndMarkTimeIsZero(int packId, int taskEffective, int taskLockTime, 
			int inspectorId, int inspectorrecordId, int inspType) {
		Map<String, Object> map = new HashMap<>();
		map.put("packId", packId);
		if(taskEffective == 0){
			map.put("taskEffective",2);
		}else{
			map.put("taskEffective",taskEffective);
		}
		if(taskLockTime>0){
			map.put("taskLockTime", taskLockTime);
		}else{
			map.put("taskLockTime", null);
		}
		map.put("inspectorId", inspectorId);
		if(inspectorrecordId>0){
			map.put("inspectorrecordId", inspectorrecordId);
		}else{
			map.put("inspectorrecordId", null);
		}
		if(inspType == 1){   //1是按包审核
			map.put("inspType", 1);
		}else{//2是快速审核
			map.put("inspType", 2);
		}
		return workerRecordMapper.updateAduitForInspectByPackageAndMarkTimeIsZero(map);
	}
	
	@Override
	public List<Integer> getPackageIdsForQuickInspection(String quickInspCondition) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("packName", "%"+quickInspCondition+"%");
		return workerRecordMapper.getPackageIdsForQuickInspection(map);
	}
	
	@Override
	public List<Map<String, Object>> getListForQuickInspection(List<Integer> packIds, String quickInspCondition, int page, int row) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("packIds", packIds);
		if (page == 0) {
			map.put("begin", null);
			map.put("end", null);
		} else {
			map.put("begin", ((page - 1) * row));
			map.put("end", row);
		}
		if(quickInspCondition.trim().length() == 0){
			map.put("packName", null);
		}else{
			map.put("packName", quickInspCondition);
		}
		return workerRecordMapper.selectForQuickInspection(map);
	}
	
	@Override
	public List<workerRecord> getTaskForQuickInspection(int packId) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("packId", packId);
		return workerRecordMapper.selectTaskForQuickInspection(map);
	}
	
	@Override
	public List<Integer> getTaskIdsForQuickInspection(int packId) {
		Map<String, Object> map = new HashMap<>();
		map.put("packId", packId);
		return workerRecordMapper.selectTaskIdsForQuickInspection(map);
	}
	
	@Override
	public List<Integer> getWorkIdsByPackIdForQuickInspection(int packId) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("packId", packId);
		return workerRecordMapper.selectWorkIdsByTaskIdForQuickInspection(map);
	}
	
	@Override
	public int updateAduitForQuickInspection(int packId, int taskEffective, int taskLockTime, int inspectorId, 
			int inspectorrecordId, int[] workerIds, int salaryCountFlag, List<AlipayInfo> payList) {
		Map<String, Object> map = new HashMap<>();
		map.put("packId", packId);
		if(taskEffective == 0){
			map.put("taskEffective",2);
		}else{
			map.put("taskEffective",taskEffective);
		}
		if(taskLockTime>0){
			map.put("taskLockTime", taskLockTime);
		}else{
			map.put("taskLockTime", null);
		}
		map.put("inspectorId", inspectorId);
		if(inspectorrecordId>0){
			map.put("inspectorrecordId", inspectorrecordId);
		}else{
			map.put("inspectorrecordId", null);
		}
		if(workerIds!=null){
			map.put("workerIds", workerIds);			
		}else{
			map.put("workerIds", null);		
		}
		if(salaryCountFlag==9){
			map.put("salaryCountFlag", null);
		}else{
			map.put("salaryCountFlag", salaryCountFlag);
		}
		//更新支付宝支付字段  需要在更新审核状态之前更新
		if(payList != null && (!payList.isEmpty())){
			for (AlipayInfo a : payList) {
				map.put("OutBizNo", a.getOutBizNo());
				map.put("alipayWorkerId", a.getWorkerId());
				workerRecordMapper.updateAlipayOutBizNoForInspectByQuickInspection(map);
			}
		}
		return workerRecordMapper.updateAduitForQuickInspection(map);
	}
	
	@Override
	public int handleWithUnqualifiedCount(int[] workerIds, String insDate, int packId, boolean quickInpsFlag, 
			String workGroupCode, int sendBackType, int[] unqualifiedTaskIds, List<String> downPackNames, 
			String uploadUUID, String searchTime, int insId, inspectorrecord inspRecord){
		Map<String, Object> map = new HashMap<>();
		map.put("workerIds", workerIds);
		map.put("insDate", insDate);
		map.put("packId", packId);
		map.put("quickInpsFlag", quickInpsFlag);
		map.put("searchTime", searchTime);		
		if(workGroupCode!=null){
			map.put("workGroupCode", workGroupCode);
		}
		map.put("sendBackType", sendBackType);
		map.put("unqualifiedTaskIds", unqualifiedTaskIds);
		map.put("downPackNames", downPackNames);
		map.put("uploadUUID", uploadUUID);
		List<Map<String,Integer>> releaseList = workerRecordMapper.selectReleaseTask(map);  //查询需要释放的任务id和记录id
		if(!releaseList.isEmpty()){  // list不为空，将相应的任务释放  
			List<Integer> recordIds = new ArrayList<Integer>();
			List<Integer> taskIds = new ArrayList<Integer>();
			for (Map<String,Integer> map2 : releaseList) {
				recordIds.add(map2.get("recordId"));
				taskIds.add(map2.get("taskId"));
			}
			//继续组装审核记录信息
			inspRecord.setInspNum(recordIds.size());
			inspectorrecordMapper.insertSelective(inspRecord);//保存审核记录
			int inspectorrecordId = inspectorrecordMapper.selectMaxIdByInspectorId(inspRecord.getInspectorid()); //获取审核记录的id
			Map<String, Object> m2 = new HashMap<>();
			m2.put("recordIds", recordIds);
			m2.put("insId", insId);
			m2.put("inspectorrecordId", inspectorrecordId);
			int count = workerRecordMapper.copyRecordToWorker939(m2); //原任务记录修改前将任务调整到工作者939的账号中
			if(count>0){
				this.taskMovedToWorker939Sendmail();
			}
			workerRecordMapper.updateWorkerRecordForReleaseTaskByWorkerRecordIds(recordIds);
			taskMapper.updateTaskForReleaseTaskByTaskIds(taskIds);
		}
		// 没有释放的任务或者释放任务之后还有剩余的不需要释放的任务  将不合格次数加1
		int count = workerRecordMapper.updateUnqualifiedCountPlusOne(map);
		return count;
	}

	@Override
	public List<String> selectDownPackNamesByTaskIds(int workerId, int[] taskIds) {
		Map<String, Object> map = new HashMap<>();
		map.put("workerId", workerId);
		map.put("taksIds", taskIds);
		return workerRecordMapper.selectDownPackNamesByTaskIds(map);
	}

	@Override
	public List<Map<String, Object>> getShowMapListForWorkerJsp(int workerId, int taskEffective, int taskStatu) {
		Map<String, Object> map = new HashMap<>();
		map.clear();
		map.put("workerId", workerId);
		map.put("taskEffective", taskEffective);
		map.put("taskStatu", taskStatu);
		if(taskEffective!=2){//下载任务列表
			return workerRecordMapper.selectShowMapListForWorkerDownList(map);
		}else{//不合格任务列表
			return workerRecordMapper.selectShowMapListForWorkerUnqualifiedList(map);
		}
	}

	@Override
	public int getWorkerDoneTaskNumForInspectionDetail(String beginDate, String endDate, int dateType) {
		Map<String, Object> map = new HashMap<>();
		map.put("dateType", dateType);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		return workerRecordMapper.selectWorkerDoneTaskNumForInspectionDetail(map);
	}

	@Override
	public List<Map<String, Object>> getDetailListForInspectionDetail(String beginDate, String endDate, int dateType) {
		Map<String, Object> map = new HashMap<>();
		map.put("dateType", dateType);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		return workerRecordMapper.selectDetailListForInspectionDetail(map);
	}

	@Override
	public Map<String, Integer> getInspDownloadCount(String beginDate, String endDate, int dateType) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("dateType", dateType);
		params.put("beginDate", beginDate);
		params.put("endDate", endDate);
		//初审下载次数
		params.put("taskEffective", 3); //已初审任务
		params.put("operationType", 4); //初审下载
		int inspByUserDLCount = workerRecordMapper.selectInspDownloadCount(params);
		//巡审下载次数
		params.put("taskEffective", 4); //已巡审任务
		params.put("operationType", 5); //巡审下载
		int inspByDayDLCount = workerRecordMapper.selectInspDownloadCount(params);
		//包审下载次数
		params.put("taskEffective", 1); //已包审任务
		params.put("operationType", 6); //包审下载
		int inspByPackageDLCount = workerRecordMapper.selectInspDownloadCount(params);
		Map<String, Integer> resultMap = new HashMap<String,Integer>();
		resultMap.put("inspByUserDLCount", inspByUserDLCount);
		resultMap.put("inspByDayDLCount", inspByDayDLCount);
		resultMap.put("inspByPackageDLCount", inspByPackageDLCount);
		return resultMap;
	}

	@Override
	public int getUninspectorCountByTaskEffectiveAndGroupCodes(int taskEffective, String[] outsourcerCodes,int type) {
		Map<String, Object> map = new HashMap<>();
		map.put("taskEffective", taskEffective);
		map.put("outsourcerCodes", outsourcerCodes);
		map.put("type", type);
		return workerRecordMapper.getUninspectorCountByTaskEffective(map);
	}

	@Override
	public double getTaskMarkTimeForUninspection(int workerId, int salaryCountTiming) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("workerId", workerId);
		map.put("salaryCountTiming", salaryCountTiming);
		return workerRecordMapper.selectTaskMarkTimeForUninspection(map);
	}

	@Override
	public List<Map<String, Object>> findUninspectWorkerRecordForFirstInspection() {
		return workerRecordMapper.findUninspectWorkerRecordForFirstInspection();
	}

	@Override
	public List<workerRecord> queryWorkerRecordByOutBizNo(String outBizNo) {
		return workerRecordMapper.queryWorkerRecordByOutBizNo(outBizNo);
	}

	@Override
	public List<Map<String, Object>> findUninspectWorkerRecordForSecondInspection() {
		return workerRecordMapper.findUninspectWorkerRecordForSecondInspection();
	}

	@Override
	public boolean inspectionByWorkerMarkTimeIsZero(int workerId, String uploadUUID, int inspectorId) {
		boolean isSuccess = false;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("workerId", workerId);
		map.put("uploadUUID", uploadUUID);
		//查询需要修改的worker record id 和task id
		List<Map<String,Integer>> idList = workerRecordMapper.queryWorkerRecordIdAndTaskIdByCondition(map);
		if(!idList.isEmpty()){  
			List<Integer> recordIds = new ArrayList<Integer>();
			List<Integer> taskIds = new ArrayList<Integer>();
			for (Map<String,Integer> map2 : idList) {
				recordIds.add(map2.get("recordId"));
				taskIds.add(map2.get("taskId"));
			}
			//根据id更新workerRecord表和task表
			map.put("inspDate", new Date());
			map.put("recordIds", recordIds);
			map.put("taskIds", taskIds);
			map.put("inspectorId", inspectorId);
			workerRecordMapper.updateWorkerRecordForFirstInspectionMarkTimeIsZeroByWorkerRecordIds(map);
			taskMapper.updateTaskForFirstInspectionMarkTimeIsZeroByTaskIds(map);
			isSuccess = true;
		}
		return isSuccess;
	}
	
	@Override
	public int countReleaseTaskNum(List<Integer> recordIds, int sendbackCount){
		Map<String, Object> map = new HashMap<>();
		map.put("sendbackCount", sendbackCount);
		map.put("recordIds", recordIds);
		int num = workerRecordMapper.countReleaseTaskNum(map);
		return num;
	}

	@Override
	public int modifySendbackCountAndReleaseTask(List<Integer> recordIds, List<Integer> taskIds, boolean releaseFlag,
			String inspectionSendbackUUID, int inspectorRecordId, int inspectorId){
		Map<String, Object> map = new HashMap<>();
		map.put("recordIds", recordIds);
		map.put("taskIds", taskIds);
		map.put("inspectionSendbackUUID", inspectionSendbackUUID);
		map.put("inspectorRecordId", inspectorRecordId);
		if(releaseFlag){
			Map<String, Object> m2 = new HashMap<>();
			m2.put("recordIds", recordIds);
			m2.put("insId", inspectorId);
			m2.put("inspectorrecordId", inspectorRecordId);
			int count = workerRecordMapper.copyRecordToWorker939(m2); //原任务记录修改前将任务调整到工作者939的账号中
			if(count>0){
				this.taskMovedToWorker939Sendmail();
			}
			workerRecordMapper.inspSecondToFirstReleaseTasks(map);
			taskMapper.updateTaskForReleaseTaskByTaskIds(taskIds);
		}
		// 没有释放的任务或者释放任务之后还有剩余的不需要释放的任务  将不合格次数加1
		int count = workerRecordMapper.updateSendbackCountPlusOne(map);
		return count;
	}

	@Override
	public int updateInspectByDaySendbackWrokerRecords(List<Integer> recordIds, int inspectorRecordId, 
			String inspectionSendbackUUID, int taskLockTime) {
		int taskEffective = 5;   //巡审退回至初审状态 5
		Map<String, Object> map = new HashMap<>();
		map.put("taskEffective", taskEffective);
		map.put("recordIds", recordIds);
		map.put("inspectionSendbackUUID", inspectionSendbackUUID);
		map.put("inspectorRecordId", inspectorRecordId);
		if(taskLockTime==0){
			map.put("taskLockTime", null);
		}else{
			map.put("taskLockTime", taskLockTime);
		}
		map.put("taskOverTime", new Date());
		return workerRecordMapper.updateInspectByDaySendbackWrokerRecords(map);
	}

	@Override
	public List<Map<String, Object>> querySendbackListByInspectorId(int inspectorId) {
		return workerRecordMapper.querySendbackListByInspectorId(inspectorId);
	}
	
	@Override
	public int querySendbackListCountByInspectorId(int inspectorId) {
		return workerRecordMapper.querySendbackListCountByInspectorId(inspectorId);
	}

	@Override
	public List<workerRecord> querySendbackWorkerRecordBySendbackUUID(String sendbackUUID, int inspectorId) {
		Map<String, Object> map = new HashMap<>();
		map.put("sendbackUUID", sendbackUUID);
		map.put("inspectorId", inspectorId);
		return workerRecordMapper.querySendbackWorkerRecordBySendbackUUID(map);
	}

	@Override
	public int updateWorkerRecordForModifyCompleted(String sendbackUUID, int inspectorId) {
		int taskEffective = 6; //初审重新提交给巡审
		Map<String, Object> map = new HashMap<>();
		map.put("taskOverTime", new Date());
		map.put("taskEffective", taskEffective);
		map.put("sendbackUUID", sendbackUUID);
		map.put("inspectorId", inspectorId);
		return workerRecordMapper.updateWorkerRecordForModifyCompleted(map);
	}

	@Override
	public List<Map<String, Object>> queryModifyCompletedList() {
		return workerRecordMapper.queryModifyCompletedList();
	}

	@Override
	public List<workerRecord> queryModifyCompletedWorkerRecordBySendbackUUID(String sendbackUUID, int inspectorId) {
		Map<String, Object> map = new HashMap<>();
		map.put("sendbackUUID", sendbackUUID);
		map.put("inspectorId", inspectorId);
		return workerRecordMapper.queryModifyCompletedWorkerRecordBySendbackUUID(map);
	}
	
	@Override
	public List<Map<String,Integer>> getTaskIdsAndWorkerrecordIdsforModifyCompleted(String sendbackUUID, String workGroupCode,int inspectorId) {
		Map<String, Object> map = new HashMap<>();
		map.put("sendbackUUID", sendbackUUID);
		map.put("workGroupCode", workGroupCode);
		map.put("inspectorId", inspectorId);
		return workerRecordMapper.selectTaskIdsForModifyCompleted(map);
	}

	@Override
	public int updateAduitForModifyCompleted(int taskEffective, int inspectorId, int inspectorrecordId, 
			int salaryCountFlag, List<AlipayInfo> payList,  List<Integer> recordIds) {
		Map<String, Object> map = new HashMap<>();
		map.put("taskEffective",taskEffective);
		map.put("inspectorId", inspectorId);
		if(inspectorrecordId>0){
			map.put("inspectorrecordId", inspectorrecordId);
		}else{
			map.put("inspectorrecordId", null);
		}
		if(salaryCountFlag==9){
			map.put("salaryCountFlag", null);
		}else{
			map.put("salaryCountFlag", salaryCountFlag);
		}
		map.put("recordIds", recordIds);
		//更新支付宝支付字段  需要在更新审核状态之前更新
		if(payList != null && (!payList.isEmpty())){
			for (AlipayInfo a : payList) {
				map.put("OutBizNo", a.getOutBizNo());
				map.put("alipayWorkerId", a.getWorkerId());
				workerRecordMapper.updateAlipayOutBizNoModifyCompleted(map);
			}
		}
		return workerRecordMapper.updateAduitForModifyCompleted(map);
		
	}

	@Override
	public List<Map<String, Object>> queryRecycledBySystemListByInspectorId(int inspectorId, int page, int row) {
		Map<String, Object> map = new HashMap<>();
		if (page == 0) {
			map.put("begin", null);
			map.put("end", null);
		} else {
			map.put("begin", ((page - 1) * row));
			map.put("end", row);
		}
		map.put("inspectorId", inspectorId);
		return workerRecordMapper.queryRecycledBySystemListByInspectorId(map);
	}

	@Override
	public int queryRecycledBySystemListByInspectorIdCount(int inspectorId) {
		return workerRecordMapper.queryRecycledBySystemListByInspectorIdCount(inspectorId);
	}

	@Override
	public List<Map<String, Object>> queryWaitingModifyList(String[] outsourcerCodes) {
		Map<String, Object> map = new HashMap<>();
		map.put("outsourcerCodes", outsourcerCodes);
		return workerRecordMapper.queryWaitingModifyList(map);
	}

	@Override
	public int releaseTasksBySendBackUUIDs(List<String> sendBackUUIDs) {
		Map<String, Object> map = new HashMap<>();
		map.put("sendBackUUIDs", sendBackUUIDs);
		//根据退回UUID查询需要释放的任务id和工作记录id
		List<Map<String,Integer>> releaseList = workerRecordMapper.queryReleaseTaskIdAndRecordIdBySendBackUUIDs(map);  //查询需要释放的任务id和记录id
		if(!releaseList.isEmpty()){  // list不为空，将相应的任务释放  
			List<Integer> recordIds = new ArrayList<Integer>();
			List<Integer> taskIds = new ArrayList<Integer>();
			for (Map<String,Integer> map2 : releaseList) {
				recordIds.add(map2.get("recordId"));
				taskIds.add(map2.get("taskId"));
			}
			Map<String, Object> m2 = new HashMap<>();
			m2.put("recordIds", recordIds);
			int count = workerRecordMapper.firstInspTimeUpCopyRecordToWorker939(m2); //任务记录修改前将任务调整到工作者939的账号中
			if(count>0){
				this.taskMovedToWorker939Sendmail();
			}
			int m = workerRecordMapper.updateWorkerRecordForModifyUncompletedByWorkerRecordIds(recordIds);
			int n = taskMapper.updateTaskForReleaseTaskByTaskIds(taskIds);
			if(m==n){
				return 1;  //释放成功
			}else{
				return 2;  //数没有对上可能存在问题
			}
		}
		return 3;   //未查询到需要更新的数据 
	}
	
	@Override
	public List<Map<String, Object>> queryModifyTimeOutListByInspectorId(int inspectorId, int page, int row) {
		Map<String, Object> map = new HashMap<>();
		if (page == 0) {
			map.put("begin", null);
			map.put("end", null);
		} else {
			map.put("begin", ((page - 1) * row));
			map.put("end", row);
		}
		map.put("inspectorId", inspectorId);
		return workerRecordMapper.queryModifyTimeOutListByInspectorId(map);
	}
	
	@Override
	public int queryModifyTimeOutListByInspectorIdCount(int inspectorId) {
		return workerRecordMapper.queryModifyTimeOutListByInspectorIdCount(inspectorId);
	}

	@Override
	public List<Map<String, Object>> queryNotReturnNums() {
		List<Map<String, Object>> totalMaps = workerRecordMapper.queryNotReturnTotal();
		List<Map<String, Object>> notUploadMaps = workerRecordMapper.queryNotReturnNotUploadNums();
		List<Map<String, Object>> waitInspNumMaps = workerRecordMapper.queryNotReturnWaitInspNums();
		List<Map<String, Object>> waitInspModificationNumMaps = workerRecordMapper.queryNotReturnWaitInspModificationNums();
		List<VtdParameter> list = paramMapper.selectAllParamByType("workGroup");	
		List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
		for (VtdParameter p : list) {		
			Map<String, Object> resultMap = new HashMap<String, Object>();
			resultMap.put("workGroupCode", p.getParamValue());		
			if(totalMaps.isEmpty()){
				resultMap.put("notReturnTotal", 0);
			}else{
				for (Map<String,Object> m1 : totalMaps) {
					if(m1.get("groupCode").equals(p.getParamValue())){
						resultMap.put("notReturnTotal", m1.get("num"));
						break;
					}else{
						resultMap.put("notReturnTotal", 0);
					}
				}
			}
			if(notUploadMaps.isEmpty()){
				resultMap.put("notUploadNum", 0);
			}else{
				for (Map<String,Object> m1 : notUploadMaps) {
					if(m1.get("groupCode").equals(p.getParamValue())){
						resultMap.put("notUploadNum", m1.get("num"));
						break;
					}else{
						resultMap.put("notUploadNum", 0);
					}
				}
			}
			if(waitInspNumMaps.isEmpty()){
				resultMap.put("waitInspNum", 0);
			}else{
				for (Map<String,Object> m1 : waitInspNumMaps) {
					if(m1.get("groupCode").equals(p.getParamValue())){
						resultMap.put("waitInspNum", m1.get("num"));
						break;
					}else{
						resultMap.put("waitInspNum", 0);
					}
				}
			}
			if(waitInspModificationNumMaps.isEmpty()){
				resultMap.put("waitInspModificationNum", 0);
			}else{
				for (Map<String,Object> m1 : waitInspModificationNumMaps) {
					if(m1.get("groupCode").equals(p.getParamValue())){
						resultMap.put("waitInspModificationNum", m1.get("num"));
						break;
					}else{
						resultMap.put("waitInspModificationNum", 0);
					}
				}
			}
			result.add(resultMap);
		}
		return result;
	}

	@Override
	public int queryWaitInspModificationNumByWorkGroupCode(String workGroupCode) {
		return workerRecordMapper.queryWaitInspModificationNumByWorkGroupCode(workGroupCode);
	}

	@Override
	public void workGroupDownloadUnlock(List<String> workGroupCodes) {
		List<Map<String, Object>> waitInspModificationNumMaps = workerRecordMapper.queryNotReturnWaitInspModificationNums();
		if(waitInspModificationNumMaps.isEmpty()){//没有初审被退回修改的任务 将工作组的backup1字段全部更新为unlock
			for (String str : workGroupCodes) {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("paramVlaue", str);
				map.put("paramType", "workGroup");
				map.put("backup1", "unlock");
				paramMapper.updateBackup1ByParamValueAndParamType(map);
			}
		}else{//查询到有初审被退回任务数的工作组总list中删除然后将其余的更新为unlock    groupCode
			for (String str : workGroupCodes) {
				boolean flag = false;
				for (Map<String, Object> m : waitInspModificationNumMaps) {
					if(m.get("groupCode").toString().equals(str)){
						flag = true;
					}
				}
				if(!flag){
					Map<String, Object> map = new HashMap<String, Object>();
					map.put("paramVlaue", str);
					map.put("paramType", "workGroup");
					map.put("backup1", "unlock");
					paramMapper.updateBackup1ByParamValueAndParamType(map);
				}
			}
		}
	}

	@Override
	public Map<String, Object> getPkIdAndUnqualifiedCountByTaskId(int taskId) {
		return workerRecordMapper.selectPkIdAndUnqualifiedCountByTaskId(taskId);
	}

	@Override
	public List<Map<String, Object>> getTaskIdsRecordIdsAndFilesForAuditingUpdateFinalMd5(int workerId, String uploadUUID) {
		Map<String, Object> map = new HashMap<>();
		map.put("workerId", workerId);
		map.put("uploadUUID", uploadUUID);
		return workerRecordMapper.queryTaskIdsRecordIdsAndFilesForAuditingUpdateFinalMd5(map);
	}

	@Override
	public int updateFinalMd5ByRecordId(int recordId, String md5) {
		Map<String, Object> map = new HashMap<>();
		map.put("recordId", recordId);
		map.put("md5", md5);
		return workerRecordMapper.updateFinalMd5ByRecordId(map);
	}

	@Override
	public List<Map<String, Object>> getTaskIdsRecordIdsAndFilesForInspectByDayUpdateFinalMd5(List<Integer> recordIds) {
		Map<String, Object> map = new HashMap<>();
		map.put("recordIds", recordIds);
		return workerRecordMapper.queryTaskIdsRecordIdsAndFilesForInspectByDayUpdateFinalMd5(map);
	}

	@Override
	public List<Map<String, Object>> getTaskIdsRecordIdsAndFilesForInspectByPackageUpdateFinalMd5(int workerId, int packId) {
		Map<String, Object> map = new HashMap<>();
		map.put("workerId", workerId);
		map.put("packId", packId);
		return workerRecordMapper.queryTaskIdsRecordIdsAndFilesForInspectByPackageUpdateFinalMd5(map);
	}

	@Override
	public List<Map<String, Object>> getTaskIdsRecordIdsAndFilesForQuickInspectionPosteUpdateFinalMd5(int workerId,	int packId) {
		Map<String, Object> map = new HashMap<>();
		map.put("workerId", workerId);
		map.put("packId", packId);
		return workerRecordMapper.queryTaskIdsRecordIdsAndFilesForQuickInspectionPosteUpdateFinalMd5(map);
	}

	@Override
	public Map<String, Object> getOneTimeSuccessRate(int workerId, String beginDate, String endDate, int dateType,
			int salaryCountTiming) {
		Map<String, Object> map = new HashMap<>();
		map.put("workerId", workerId);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		map.put("dateType", dateType);
		map.put("salaryCountTiming", salaryCountTiming);
		//返回下载任务总数 downAllNum, 未上传数 notUploadNum, 未结算数 notSettlementNum, 一次性成功数 oneTimeSuccessNum, 一次性成功率oneTimeSuccessRate
		//下载任务总数 downAllNum
		int downAllNum = workerRecordMapper.queryAllDownloadNumByworkerIdAndDate(map);
		//未上传数 notUploadNum
		int notUploadNum = workerRecordMapper.queryNotUploadNumByworkerIdAndDate(map);
		//未结算数 notSettlementNum //未审核
		int notSettlementNum = workerRecordMapper.queryNotSettlementNumByworkerIdAndDate(map);
		//超时任务数
		int overTimeNum = workerRecordMapper.queryOverTimeNumByworkerIdAndDate(map);
		//放弃任务数
		int giveUpNum = workerRecordMapper.queryGiveUpNumByworkerIdAndDate(map);
		//多次修改错误被回收任务数
		int systemTakeBackNum = workerRecordMapper.querySystemTakeBackNumByworkerIdAndDate(map);
		//错误数  被修改过的记录数
		int modifyNum = workerRecordMapper.queryModifyNumByworkerIdAndDate(map);
		//一次性成功数 oneTimeSuccessNum
		int oneTimeSuccessNum = workerRecordMapper.queryOneTimeSuccessNumByworkerIdAndDate(map);
		DecimalFormat df = new DecimalFormat("#.00");
		String oneTimeSuccessRate;
		if(downAllNum-notUploadNum-notSettlementNum>0){
			oneTimeSuccessRate = df.format(((double)oneTimeSuccessNum/(double)(downAllNum-notUploadNum-notSettlementNum))*100)+"%";
		}else{
			oneTimeSuccessRate = "-";
		}
//		System.out.println("总下载任务数: "+downAllNum+" 未上传任务数: "+notUploadNum+" 为结算数: "
//				+notSettlementNum+" 一次性成功数: "+oneTimeSuccessNum+" 一次性成功率: "+ oneTimeSuccessRate);
		Map<String, Object> result = new HashMap<>();
		result.put("downAllNum", downAllNum);
		result.put("notUploadNum", notUploadNum);
		result.put("notSettlementNum", notSettlementNum);
		result.put("oneTimeSuccessNum", oneTimeSuccessNum);
		result.put("oneTimeSuccessRate", oneTimeSuccessRate);
		result.put("overTimeNum", overTimeNum);
		result.put("giveUpNum", giveUpNum);
		result.put("systemTakeBackNum", systemTakeBackNum);
		result.put("modifyNum", modifyNum);
		return result;
	}

	@Override
	public int queryUploadCountByDate(String queryDate) {
		Map<String, Object> map = new HashMap<>();
		map.put("queryDate", queryDate);
		return workerRecordMapper.queryUploadCountByDate(map);
	}

	@Override
	public List<Map<String, Object>> getWorkerUploadTime(int dateType, String beginDate, String endDate,
			String userNameCondition, String workGroupCode) {
		List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
		//参数map
		Map<String, Object> map = new HashMap<>();
		map.put("workGroupCode", workGroupCode);
		map.put("dateType", dateType);
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		if(userNameCondition.trim().length() != 0){
			map.put("userNameCondition", userNameCondition);
		}else{
			map.put("userNameCondition", null);
		}
		//查询符合条件的工作者id
		List<Map<String,Object>> resultList  = workerRecordMapper.selectByWorkGroupCodeAndUploadTimeAndUsername(map);
		//根据id查询上传时间数据
		for (Map<String, Object> m1 : resultList) {
			map.remove("workerId");
			int workerId = Integer.parseInt(m1.get("workerId").toString());
			map.put("workerId", workerId);
			double uninspectionTime = workerRecordMapper.selectUninspectionTimeUploadTimeByWorkerId(map);
			double inspectedTime = workerRecordMapper.selectInspectedTimeUploadTimeByWorkerId(map);
			m1.put("uninspectionTime", uninspectionTime);
			m1.put("inspectedTime", inspectedTime);
		}
		return resultList;
	}
	
	private void taskMovedToWorker939Sendmail(){
		//发送邮件提醒工作者939
		//编辑邮件内容
    	StringBuilder sb = new StringBuilder();
		sb.append("有任务被回收至账号rwxz01中,请及时处理!");
		sb.append("<br/>");
		sb.append("<br/>");
		sb.append("本邮件为系统自动发出请不要回复谢谢！");
		String title = "任务被回收提示";
    	// 剩余5天开始提示给管理员发邮件  剩余3天扩大邮件范围  页面给管理员弹提示框 改变背景颜色
		TaskMovedToWorker939MailSender m = new TaskMovedToWorker939MailSender();
		try {
			m.sendMail(sb.toString(),title);
		} catch (MessagingException e) {
			e.printStackTrace();
			System.out.println("邮件发送出错！！！" );
		} catch (GeneralSecurityException e) {
			e.printStackTrace();
			System.out.println("邮件发送出错！！！" );
		}		
	}

	@Override
	public int getWorkerIdCountGroupByWorkerId(int inspectorId, String userName, int timeMark, int taskStatu,
			int taskEffective, int limitMin, String workGroupCode, String packBatchName) {
		Map<String, Object> map = new HashMap<>();

		map.clear();
		if (userName.isEmpty() || userName.trim().length() == 0) {
			map.put("userName", null);
		} else {
			map.put("userName", userName);
		}
		if(inspectorId == -1){
			map.put("inspectorId", null);
		}else if(inspectorId >= 0){
			map.put("inspectorId", inspectorId);
		}
		if(workGroupCode!=null && (!workGroupCode.equals(""))){
			map.put("workGroupCode", workGroupCode);
		}
		if(packBatchName.equals("")){
			map.put("packBatchName", null);
		}else{
			map.put("packBatchName", packBatchName);
		}
		map.put("taskStatu", taskStatu);
		map.put("taskEffective", taskEffective);
		return workerRecordMapper.selectWorkerIdCountGroupByWorkerIdConditionByPackBatchName(map);
	}

	@Override
	public List<Map<String, Object>> getWorkerIdGroupByWorkerId(int inspectorId, String userName, int timeMark,
			int taskStatu, int taskEffective, int page, int row, int limitMin, String workGroupCode,
			String packBatchName) {
		Map<String, Object> map = new HashMap<>();
		map.clear();
		if (page == 0) {
			map.put("begin", null);
			map.put("end", null);
		} else {
			map.put("begin", ((page - 1) * row));
			map.put("end", row);
		}
		if (userName.isEmpty() || userName.trim().length() == 0) {
			map.put("userName", null);
		} else {
			map.put("userName", userName);
		}
		if(inspectorId == -1){
			map.put("inspectorId", null);
		}else if(inspectorId >= 0){
			map.put("inspectorId", inspectorId);
		}
		if(workGroupCode!=null && (!workGroupCode.equals(""))){
			map.put("workGroupCode", workGroupCode);
		}
		map.put("taskStatu", taskStatu);
		map.put("taskEffective", taskEffective);
		if(packBatchName.equals("")){
			map.put("packBatchName", null);
		}else{
			map.put("packBatchName", packBatchName);
		}
		return workerRecordMapper.selectWorkerIdGroupByWorkerIdConditionByPackBatchName(map);
	}

	@Override
	public int getWorkerDownloadTaskNumByWorkerId(int workerId) {
		return workerRecordMapper.selectWorkerDownloadTaskNumByWorkerId(workerId);
	}

	@Override
	public int changeWorkerDownloadTaskLockTimeByWorkerId(int workerId, long lockTime) {
		Map<String, Object> map = new HashMap<>();
		map.put("workerId", workerId);
		map.put("lockTime", lockTime);
		return workerRecordMapper.updateWorkerDownloadTaskLockTimeByWorkerId(map);
	}

	@Override
	public boolean updateWorkerRecordChangeZeroTo0001(int workerId, String uploadUUID) {
		Map<String, Object> map = new HashMap<>();
		map.put("workerId", workerId);
		map.put("uploadUUID", uploadUUID);
		return workerRecordMapper.updateWorkerRecordChangeZeroTo0001(map);
	}
	
}
